<?php
/**
 * Created by Haobin.
 * User: HaoBin
 * Date: 2016/8/11
 * Time: 9:10
 */
session_start();
require('../conn.php');
require('../functions.php');
require('admin.php');

if ($_POST['do'] == 'admin' && $_POST['admin_username'] != null) {
    $admin_username = guolv($_POST['admin_username']);
    $admin_password = guolv($_POST['admin_password']);

    $row = $mysql->query("select * from `about` where `name`='{$admin_username}' limit 1");
    if (!$row) {
        $mysql->query("insert into `about` values(null,'{$admin_username}','{$admin_password}')");
        $id = mysql_insert_id();
        if ($id !== 0) {
            echo "<script>alert('增加成功！');location.href='about.php'</script>";
            exit;
        }
    }
}
if (is_numeric($_GET['del_admin'])) {
    $del_admin = guolv($_GET['del_admin']);
    $mysql->query("delete from `about` where `id`='{$del_admin}'");
    echo '<script>alert(\'删除成功！\');location.href=\'about.php\'</script>';
    exit;
} ?>

<?php include('head.php') ?>
<div class="container-fluid">

    <div class="row-fluid">
        <?php
        include('left.php'); ?>
        <div class="span10">
            <h1 class="page-title">关于设置</h1>

            <div class="well">
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#admin" data-toggle="tab">新增连接</a></li>

                </ul>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="admin">
                        <form action="about.php" method="post">
                            <input type="hidden" name="do" value="admin">
                            <label>名称：</label>
                            <input type="text" value="" style="width:210px" name="admin_username">
                            <label>连接：</label>
                            <input type="text" value="" style="width:210px" name="admin_password">
                            <div>
                                <button class="btn btn-primary">提交</button>
                            </div>
                        </form>
                        <div class="well">
                            <table class="table">
                                <thead>
                                <tr>
                                    <th>名称</th>
                                    <th>连接</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                $row_admin = $mysql->query("select * from `about` order by `id` desc");
                                foreach ($row_admin as $v_admin) {
                                    print <<<table
        <tr>
          <td>{$v_admin['name']}</td>
		   <td>{$v_admin['link']}</td>
		  <td>
			<a class="btn btn" href="?del_admin={$v_admin['id']}">删除</a>
		  </td>
        </tr>
table;
                                } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>

            </div>

        </div>
    </div>

</div>

<footer>
    <hr>

    <p class="pull-right"><!--power by right--></p>


    <p><!--power by --></p>
</footer>


<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="lib/bootstrap/js/bootstrap.js"></script>
</body>
</html>